package com.pcitc.app.webapp.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.pcitc.app.service.TblUserManager;
import com.pcitc.app.webapp.action.vo.tblUserVo;
import com.pcitc.app.model.TblPosition;
import com.pcitc.app.model.TblUser;
import com.pcitc.app.model.TblOrg;;
/**
 * 
 * @author xiayihua
 * 
 */ 
public class SingupAction extends BaseAction implements ModelDriven{
	private tblUserVo info =new tblUserVo();
	public Object getModel() {
		// TODO Auto-generated method stub
		return info;
	}
	
	//private TblUser tbluser = null;
	@SuppressWarnings("unchecked")
	/**
	 * @author zhangbin
	 * 保存用户的注册信息
	 * @return
	 */
	public String saveUser() throws Exception{	

		TblOrg org=tblOrgManager.loadOrgByOrgid(info.getTblorg().getOrgid());
		TblUser tbluser=info.getTbluser();
		tbluser.setTblOrg(org);
		tblUserManager.saveUser(tbluser);
		return SUCCESS;
	}	
	/**
	 * @author zhangbin
	 * 获取组织机构信息返回到注册页面
	 * @return
	 */
	public String getOrgList(){	
		List<TblOrg> orgsList=tblOrgManager.getOrgList();
		info.setOrgsList(orgsList);
		return SUCCESS;		
	}
	
	/**
	 * @author zhangbin
	 * 根据组织机构id获取岗位列表
	 * @return
	 */
	public String getPosition(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String orgid=request.getParameter("orgid");
		List<TblPosition> tblpositionList=tblOrgManager.getPositionListByOrgId(new Long(orgid));
		info.setPositionList(tblpositionList);
		return SUCCESS;
	}
	
	
}
